﻿
using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;
using System.Web;
using YouHP.Model.Group;

namespace YouHP.Pages
{
    public class DoctorList : BasePage
    {
        protected override void ShowPage()
        {
            base.ShowPage();
            if(ErrorCount > 0) return;
            
            HandleCommon();
            if(ErrorCount > 0) return;
            
            if(IsPost) HandlePost();
            else HandleGet();
        }

        protected List<DoctorInfo> _doctorInfoList;

        protected int _diseaseId = 0;
        protected int _recordCount = 0;
        protected int _pageCount = 0;
        protected int _pageSize = 8;
        protected int _pageIndex = 1;
        protected string _pagingString;

        protected void HandleCommon()
        {
            _diseaseId = RequestTools.GetQueryInt("diseaseid", 0);
            if (_diseaseId <= 0)
            {
                this.AddErrLine("错误的疾病ID");
                return;
            }

            bool userLogin = UserData != null && UserData.Id > 0;
            if (userLogin == false)
            {
                this.AddLocation("中药列表", "/PrescriptionAll.aspx");
            }

            string diseaseName = DiseaseBLL.Instance.GetDiseaseInfo(_diseaseId).Name;
            this.AddLocation("<font color=\"red\">" + diseaseName + "</font>" + "&nbsp;中药列表", "");
            this.SetTitle(diseaseName+"中药列表");
        }
        
        protected void HandlePost()
        {
            
        }

        protected void HandleGet()
        {
            // Handle exceptions.
            if (_diseaseId <= 0)
            {
                this.AddErrLine("错误的疾病ID");
                return;
            }

            _pageIndex = RequestTools.GetQueryInt("page", 1);
            _doctorInfoList = DoctorBLL.Instance.GetDoctorListEx(_pageSize, _pageIndex, _diseaseId, out _recordCount);

            string query = HttpContext.Current.Request.Url.Query;
            query = Utils.RemoveQueryItem(query, "page");
            _pageCount = Utils.GetPageCount(_recordCount, _pageSize);
            _pagingString = this.GetPagingString(_pageIndex, _pageCount, "/DoctorList.aspx" + query, "page");
        }
    }
}